package dao;

import org.apache.ibatis.annotations.*;
import pojo.JxbZz;

import java.util.List;

@Mapper
/**
 * 疾病症状关联表数据访问接口
 */
public interface JxbZzMapper {
    // 根据疾病ID查询症状关联
    @Select("SELECT jxb_id, zz_id, weight FROM jxb_zz WHERE jxb_id = #{jxbId}")
    List<JxbZz> findByJxbId(Integer jxbId);

    // 根据症状ID查询疾病关联
    @Select("SELECT jxb_id, zz_id, weight FROM jxb_zz WHERE zz_id = #{zzId}")
    List<JxbZz> findByZzId(Integer zzId);

    // 查询疾病-症状关联
    @Select("SELECT jxb_id, zz_id, weight FROM jxb_zz WHERE jxb_id = #{jxbId} AND zz_id = #{zzId}")
    JxbZz findByJxbAndZz(Integer jxbId, Integer zzId);

    // 批量添加关联关系
    @Insert({"<script>",
            "INSERT INTO jxb_zz (jxb_id, zz_id, weight) VALUES",
            "<foreach collection='list' item='item' separator=','>",
            "(#{item.jxbId}, #{item.zzId}, #{item.weight})",
            "</foreach>",
            "</script>"})
    int batchAdd(List<JxbZz> jxbZzList);

    // 添加单个关联关系
    @Insert("INSERT INTO jxb_zz (jxb_id, zz_id, weight) VALUES (#{jxbId}, #{zzId}, #{weight})")
    int add(JxbZz jxbZz);

    // 更新关联权重
    @Update("UPDATE jxb_zz SET weight = #{weight} WHERE jxb_id = #{jxbId} AND zz_id = #{zzId}")
    int updateWeight(JxbZz jxbZz);

    // 删除疾病关联的所有症状
    @Delete("DELETE FROM jxb_zz WHERE jxb_id = #{jxbId}")
    int deleteByJxbId(Integer jxbId);

    // 删除症状关联的所有疾病
    @Delete("DELETE FROM jxb_zz WHERE zz_id = #{zzId}")
    int deleteByZzId(Integer zzId);

    // 删除单个关联关系
    @Delete("DELETE FROM jxb_zz WHERE jxb_id = #{jxbId} AND zz_id = #{zzId}")
    int deleteByJxbAndZz(Integer jxbId, Integer zzId);
}